package com.qj.sys.controller;

import com.qj.bean.Result;
import com.qj.sys.entity.dto.UserDto;
import com.qj.sys.entity.dto.UserPageDto;
import com.qj.sys.entity.req.UserPageReq;
import com.qj.sys.entity.req.UserReq;
import com.qj.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author dlw
 * @date 2025-05-13 11:56
 */
@RestController
@RequestMapping("/user")
//swagger设置
@Api(tags = "用户Controller")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/addUser")
    //swagger注解
    @ApiOperation(value = "新增用户")
    public int addUser(@RequestBody UserReq userReq) {
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReq, userDto);
        int count = userService.addUser(userDto);
        return count;
    }

    @DeleteMapping("/deleteUser/{id}")
    public Result deleteUser(@PathVariable Integer id) {
        return Result.ok(userService.deleteUser(id));
    }

    @GetMapping("/getUserPage")
    public Result getUserPage(@RequestBody UserPageReq userPageReq) {
        UserPageDto userPageDto = new UserPageDto();
        BeanUtils.copyProperties(userPageReq, userPageDto);
        return Result.ok(userService.getUserPage(userPageDto));
    }

}
